#include "gd32w51x.h"
#include "DevicesDelay.h"
#include "DevicesPower.h"



void vPowerInit(void)
{
    /* enable the GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_GPIOC);

    /* configure GPIO pin */
    gpio_mode_set(POWER_COM_GPIO_Port, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, POWER_COM_Pin);
    gpio_output_options_set(POWER_COM_GPIO_Port, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, POWER_COM_Pin);

    gpio_mode_set(POWER_MCU_GPIO_Port, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, POWER_MCU_Pin);
    gpio_output_options_set(POWER_MCU_GPIO_Port, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, POWER_MCU_Pin);


    vPowerOpen(POWER_ALL);

    vPowerClose(POWER_MCU);
    vDelayMs(1000);

    vPowerOpen(POWER_ALL);
}

void vPowerOpen(uint16_t usNumber)
{
    if(usNumber & POWER_COM)
    {
        POWER_COM_ENABLE();
    }
    if(usNumber & POWER_MCU)
    {
        POWER_MCU_ENABLE();
    }
}

void vPowerClose(uint16_t usNumber)
{
    if(usNumber & POWER_COM)
    {
        POWER_COM_DISABLE();
    }
    if(usNumber & POWER_MCU)
    {
        POWER_MCU_DISABLE();
    }
}
